package timer_update

import (

	// "encoding/json"
	"PackingScanApp/db_mysql_server"
	"PackingScanApp/models"
	"time"
)

var (
	ticker = time.NewTicker(1 * time.Hour)
)

func init() {
	go timerRun()
}

func timerRun() {
	for {
		select {
		case <-ticker.C:
			var barcodepackings []models.Barcodepacking
			var barcodepackinglists []models.Barcodepackinglist
			if err1 := db_server_mysql.SelectBarcodepacking_list(&barcodepackings); err1 == nil {
				for _, val1 := range barcodepackings {
					if _, err_up1 := db_server_mysql.InsertBarcodepacking_S40(&val1); err_up1 == nil {
						db_server_mysql.UpdateBarcodepacking_isupdate(val1.Id)
					}
				}
			}

			if er2 := db_server_mysql.SelectBarcodepackinglist_List(&barcodepackinglists); er2 == nil {
				for _, val2 := range barcodepackinglists {
					if err_up2 := db_server_mysql.InsertBarcodepackinglist_S40(&val2); err_up2 == nil {
						db_server_mysql.UpdateBarcodepackinglist_isupdate(val2.Id)
					}
				}
			}
		} //--select End
	}
}
